export const getQueryString = name => {
  var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i')

  var r = window.location.search.substr(1).match(reg)
  if (r != null) {
    return unescape(r[2])
  }
  return null
}

export const fmtDate = (obj) => {
  var date = new Date(obj)
  var y = 1900 + date.getYear()
  var m = '0' + (date.getMonth() + 1)
  var d = '0' + date.getDate()
  return y + '-' + m.substring(m.length - 2, m.length) + '-' + d.substring(d.length - 2, d.length)
}

export const formatDate = (obj) => {
  var date = new Date(obj)
  var y = 1900 + date.getYear()
  var m = '0' + (date.getMonth() + 1)
  var d = '0' + date.getDate()
  return m.substring(m.length - 2, m.length) + '-' + d.substring(d.length - 2, d.length)
}

export const getWeek = (dateString) => {
  let date
  let dateArray = dateString.split('-')
  date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2])
  return '周' + '日一二三四五六'.charAt(date.getDay())
}
